<div class="layui-fluid" id="VIEW-list-table" lay-title="字典管理">
    <div class="layui-row layui-col-space12">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body nepadmin-table-full">
                    <div class="layui-btn-container nepadmin-pad-t10 nepadmin-pad-l10">
                        <div class="layui-btn layui-btn-sm add" >添加字典</div>
                        <div class="layui-btn layui-btn-sm layui-btn-primary table-action" data-type="del">删除</div>
                    </div>
                    <table id="list-table-dict" lay-filter="list-table-dict"></table>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['admin', 'table', 'form', 'jquery','view'], function () {
        var $ = layui.jquery
            , layer = layui.layer
            , form = layui.form
            , view = layui.view
            , admin = layui.admin
            , table = layui.table;
        var viewList = $('#VIEW-list-table');
        var tableFilter = 'list-table-dict';

        table.render({
            elem: '[lay-filter="' + tableFilter + '"]',
            //api: 'getGoods',
            url: '/sysDict/page?token=' + admin.loginToken,
            height: 'full-165',
            cols: [[
                {title: '', type: 'checkbox', fixed: true, width: 60},
                {title: '字典名称', field: 'name'},
                {title: '字典类型', field: 'dictType'},
                {
                    title: '状态', width: 80, templet: function (d) {
                        var status = {
                            1: {title: '启用', color: 'blue'},
                            0: {title: '禁用', color: 'orange'}
                        }[d.status];
                        return '<span class="layui-badge layui-bg-' + status.color + '">' + status.title + '</span>';
                    }
                },
                {
                    title: '操作时间', field: 'time', align: 'center', minWidth: 250, templet: function (d) {
                        var createTime = layui.util.toDateString(d.createTime, 'yyyy-MM-dd')
                        return '<p><span title="' + d.createTime + '" class="nepadmin-c-gray">' + createTime + '</span></p>';
                    }
                },
                {
                    title: '操作', width: 220, align: 'center', templet: function (d) {
                        var editBtn = '<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">编辑</a>';
                        var listBtn = '<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="list">列表</a>';
                        var delBtn = '<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>';
                        return editBtn + listBtn + delBtn;
                    }
                }
            ]]
        });

        table.on('tool(' + tableFilter + ')', function (obj) {
            if (obj.event === 'list') {//字典数据
                var dictType = obj.data.dictType;
                var dictId = obj.data.id;
                // 重新打开一个tab页
                var href = '#/sys/dict/sysDictDataList/dictType='+dictType+'/dictId='+dictId;
                //view.tab.del(href)
                //admin.initView(href);
                admin.navigate(href)

                //view.tab.clear();

            } else if (obj.event === 'del') {//删除行

            } else if (obj.event === "edit") {
                admin.popup({
                    url: '/sys/dict/sysDictEdit',
                    area: ['650px', '450px'],
                    data : {
                        table:table,
                        dictId : obj.data.id
                    }
                })
                return false
            }
        });

        viewList.find('.add').on("click", function () {
            admin.popup({
                    url: '/sys/dict/sysDictEdit',
                    area: ['650px', '450px'],
                    data : {
                        table:table
                    }
                }
            )
            return false
        });

        viewList.find('.table-action').click(function () {
            var checkedCount = table.checkStatus(tableFilter).data.length;
            if (checkedCount == 0) {
                layer.msg('请先选择某行');
            } else {
                layer.msg($(this).html() + checkedCount + '项');
            }
        })

    })
</script>